<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 2.求一组数中的最大值和最小值，以及所在位置
    let arr = [11, 22, 5, 23, 54, 9, 18];
    let max = arr[0],
        min = arr[0],
        max_index, min_index;
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] > max) {
            max = arr[i];
            max_index = i;
        }
        if (arr[i] < min) {
            min = arr[i];
            min_index = i;
        }
    }
    console.log('最大值:' + max + '下标为：' + max_index);
    console.log('最小值' + min + '下标为：' + min_index);
    // 3.将字符串数组用|或其他符号分割   
    let names = ["卡卡西", "佐助", "鸣人", "大蛇丸", "雏田", "小苏", "凤姐", "黑崎一护"];
    let str = '';
    for (let i = 0; i < names.length - 1; i++) {
        str += names[i] + '|';
    }
    str += names[names.length - 1];
    console.log(str);
    // 4.要求将数组中的0项去掉，将不为0的值存入一个新的数组，生成新的数组
    let a = [3, 5, 10, 0, 7, 39, 62, 0, 6, 43]
    let new_a = [];
    for (let k in a) {
        if (a[k] != 0) {
            new_a.push(a[k]);
        }
    }
    console.log(new_a);

    // 5.反转数组
    console.log('数组', a)
    let temp;
    for (let i = 0; i < parseInt(a.length / 2); i++) {
        temp = a[i];
        a[i] = a[a.length - 1 - i];
        a[a.length - 1 - i] = temp;
    }
    console.log('交换反转：', a);


    let re_a = [];
    for (let i = a.length - 1; i >= 0; i--) {
        re_a.push(a[i]);
    }
    console.log('反转数组:', re_a);
    console.log('反转函数反转：', re_a.reverse());

    // 6.提示用户输入班级人数,求总成绩,平均值,最高分,最低分
    let num = parseInt(prompt("请输入班级人数"));
    let scores = [];
    let total = 0;
    for (let i = 1; i <= num; i++) {
        scores[i] = parseInt(prompt("请输入第" + i + "位学生的成绩"));
        total += scores[i];
    }
    console.log(scores);
    let first = scores[1],
        last = scores[1];
    for (let i = 2; i < scores.length; i++) {
        first = first > scores[i] ? first : scores[i];
        last = last < scores[i] ? last : scores[i];
    }
    console.log('总成绩:', total);
    console.log('平均值:', total / num);
    console.log('最高分:', first);
    console.log('最低分:', last);
</script>

</html>